home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / x11 / rpg / crossfir.92 / crossfir / crossfire-0.92.5 / crossedit / Cnv / CnvBrowse.c < prev    next >
C/C++ Source or Header  |  1996-07-24  |  3KB  |  156 lines

  1. #include <Cnv.h>
  2.  
  3. /**********************************************************************
  4.  * widget
  5.  **********************************************************************/
  6.  
  7. static void CancelCb(Widget w,XtPointer client,XtPointer call)
  8. {
  9.   CnvBrowse self = (CnvBrowse)client;
  10.   XtPopdown(self->shell);
  11.   self->isup = False;
  12. }
  13.  
  14. static void OkCb(Widget w,XtPointer client,XtPointer call)
  15. {
  16.   CnvBrowse self = (CnvBrowse)client;
  17.   String str;
  18.  
  19.   XtPopdown(self->shell);
  20.   XtUnmanageChild(self->ok);
  21.   self->isup = False;
  22.   XtVaGetValues(self->text,
  23.         XtNstring,&str,
  24.         NULL);
  25.   (*self->proc)(self,client,str);
  26. }
  27.  
  28. /**********************************************************************
  29.  * privates
  30.  **********************************************************************/
  31.  
  32. static void Layout(CnvBrowse self,String name,Widget parent)
  33. {
  34.   Widget vpaned,hbox,cancel;
  35.  
  36.   self->shell = XtVaCreatePopupShell
  37.       (name,topLevelShellWidgetClass,parent,
  38.        NULL);
  39.   vpaned = XtVaCreateManagedWidget
  40.       ("vpaned",panedWidgetClass,self->shell,
  41.        XtNorientation,XtorientVertical,
  42.        NULL);
  43.   hbox = XtVaCreateManagedWidget
  44.       ("hbox",boxWidgetClass,vpaned,
  45.        XtNorientation,XtorientHorizontal,
  46.        XtNshowGrip,False,
  47.        NULL);
  48.  
  49.   cancel = XtVaCreateManagedWidget
  50.       ("cancel",commandWidgetClass,hbox,
  51.        NULL);
  52.   XtAddCallback(cancel,XtNcallback,CancelCb,(XtPointer)self);
  53.  
  54.   self->ok = XtVaCreateWidget
  55.       ("ok",commandWidgetClass,hbox,
  56.        NULL);
  57.   XtAddCallback(self->ok,XtNcallback,OkCb,(XtPointer)self);
  58.  
  59.   self->file = XtVaCreateWidget
  60.       ("file",labelWidgetClass,hbox,
  61.        NULL);
  62.   self->text = XtVaCreateManagedWidget
  63.       ("text",asciiTextWidgetClass,vpaned,
  64.        XtNeditType,XawtextEdit,
  65.        NULL);
  66. }
  67.  
  68. static void CnvBrowseShow(CnvBrowse self)
  69. {
  70.   XtUnmanageChild(self->file);
  71.   if(self->isup == False) XtPopup(self->shell,XtGrabNone);
  72. }
  73.  
  74. /**********************************************************************
  75.  * members
  76.  **********************************************************************/
  77.  
  78. /*
  79.  * parent:
  80.  * byName:
  81.  */
  82. CnvBrowse CnvBrowseCreate
  83. (String name,Widget parent,CnvBrowseEditProc proc)
  84. {
  85.     CnvBrowse self;
  86.     
  87.     /* alloc & init state */
  88.     self = (CnvBrowse)XtMalloc(sizeof(struct CnvBrowse));
  89.     self->shell = NULL;
  90.     self->text = NULL;
  91.     self->file = NULL;
  92.     self->isup = False;
  93.     self->proc = proc;
  94.    
  95.     Layout(self,name,parent);
  96.     return self;
  97. }
  98.  
  99. /*
  100.  *
  101.  */
  102. void CnvBrowseDestroy(CnvBrowse self)
  103. {
  104.   XtDestroyWidget(self->shell);
  105.   XtFree((char*)self);
  106. }
  107.  
  108. /*
  109.  * show file
  110.  */
  111. void CnvBrowseShowFile(CnvBrowse self,String file)
  112. {
  113.     if(!(self && file)) return;
  114.     CnvBrowseShow(self);  
  115.     XtManageChild(self->file);
  116.     XtVaSetValues(self->text,
  117.           XtNtype,XawAsciiFile,
  118.           XtNstring,file,
  119.           XtNeditType,XawtextRead,
  120.           NULL);
  121.     XtVaSetValues(self->file,
  122.           XtNlabel,file,
  123.           NULL);
  124. }
  125.  
  126. /*
  127.  * show string
  128.  */
  129. void CnvBrowseShowString(CnvBrowse self,String str)
  130. {
  131.     if(!(self && str)) return;
  132.     CnvBrowseShow(self);
  133.     XtVaSetValues(self->text,
  134.           XtNtype,XawAsciiString,
  135.           XtNstring,str,
  136.           XtNeditType,XawtextRead,
  137.           NULL);
  138. }
  139.  
  140. /*
  141.  * edit string, finish by callback
  142.  */
  143. void CnvBrowseEditString(CnvBrowse self,String str)
  144. {
  145.     if(!(self && str && self->proc)) return;
  146.     XtManageChild(self->ok);
  147.     CnvBrowseShow(self);
  148.     XtVaSetValues(self->text,
  149.           XtNtype,XawAsciiString,
  150.           XtNstring,str,
  151.           XtNeditType,XawtextEdit,
  152.           NULL);
  153. }
  154.  
  155. /*** end of CnvBrowse.c ***/
  156.